<template>
	<view class="news">
		<view @click="navigion(item.id)"  class="news_item" v-for="item in newsList" :key="item.id">
			<image :src="item.img_url"></image>
			<view class="right">
				<view class="title">
					{{item.title}}
				</view>
				<view class="info">
					<text>发布日期:{{item.add_time | formatDate}}</text>
					<text>浏览:{{item.click}}</text>
					
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:['newsList'],
		filters:{
			// 过滤日期
			formatDate(date){
				
				const newDate = new Date(date)
				const year = newDate.getFullYear()
				const month = newDate.getMonth() + 1
				const day   = newDate.getDate()
				return year+'-'+month+'-'+day
			}
		},
		methods:{
			// 调用父组件的方法
			navigion(id){
				console.log('sun',id)
				this.$emit('itemClick',id)
			}
		}
	}
</script>

<style lang="scss">
	.news{
		.news_item{
			padding: 10rpx 20rpx;
			display: flex;
			border: 1px solid #007AFF;
			image{
				width: 200rpx;
				height: 200rpx;
				padding-right: 20rpx;
			}
			.right{
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.title{
					font-size: 30rpx;	
			}
			.info{
				font-size: 26rpx;
				text:nth-child(2){
					margin-left: 30rpx;
				}
			}
			}
			
		}
	}
</style>
